<?php
/**
 * 买入套件订单
 * @version $Id$
 */
class KitorderAction extends BaseAction {
	protected $order,$area_list,$_role;
	function _initialize() {
		parent::_initialize();
		$this->_role = 14;
		self::exist_role(array(14,1));
		$this->order=new KitOrder();
		//订单状态：0未处理 1代理商已受理 2区专营商已受理 3市专营商已受理 4省专营商已受理  5云采购已受理  6已完成 7已取消
		$order_status = array(	0=>'未处理 ',
								1=>'代理商已受理 ',
								2=>'区专营商已受理 ',
								3=>'市专营商已受理  ',
								4=>'省专营商已受理 ',
								5=>'云采购已受理 ',
								6=>'已完成  ',
								7=>'已取消 '
								);
		$this->assign('order_status',$order_status);
		//支付状态：0未支付  1已支付
		$order_pay = array(0=>'未支付',1=>'已支付');
		$this->assign('order_pay',$order_pay);
		//出货状态：0未出货  1已出货
		$order_shipping = array(0=>'未出货',1=>'已出货');
		$this->assign('order_shipping',$order_shipping);
		//结算状态：0未结算 1已结算
		$order_checkout = array(0=>'未结算',1=>'已结算');
		$this->assign('order_checkout',$order_checkout);
		/**
		 * 订单详细页
		 * */		
		//产品类型：1云购商 2云购店 3代理商
		$goods_type = array(1=>'云购商',2=>'云购店 ',3=>'代理商');
		$this->assign('goods_type',$goods_type);
		//操作状态：0无效 1生效
		$log_status = array(0=>'无效',1=>'生效 ');
		$this->assign('log_status',$log_status);
		//操作类型：0用户下单 受理：1代理商 2区专营商 3市专营商 4省专营商 5云采购 6完成 7取消 8修改 9支付 10出货 11结算
		$oper_type = array(0=>'用户下单',1=>'代理商 ',2=>'区专营商 ',3=>'市专营商  ',4=>'省专营商 ',5=>'云采购  ',
							6=>'完成 ',7=>'取消 ',8=>'修改 ',9=>'支付 ',10=>'出货 ',11=>'结算 ');
		$this->assign('oper_type',$oper_type);
		
		$area=F('Area');
        if(empty($area)){
            $area=M('Area')->select();
            $area=field2key($area,'id');
            F('Area',$area);
        }
		$this->area_list = $area;
        $this->assign('Area_list',$area);
	}
    public function index(){
		$condition=array();
		
		if($this->keywords){
            $wherefields=explode(',',$_REQUEST['sfield_name']);
            if(in_array($_REQUEST['wherefields'], $wherefields)){
                $wherefields=$_REQUEST['wherefields'];
                $condition[$wherefields]=array("like",'%'.$this->keywords.'%');
                $this->assign('wherefields',$wherefields);
            }else{
            	$map=array();
                foreach ($wherefields as $value) {
                    $map[$value]=array("like",'%'.$this->keywords.'%');
                }
                $map['_logic'] = 'or';
                $condition['_complex'] = $map;
                $this->assign('wherefields','all');
            }
        }
		//订单区域条件查询
		$province= intval($_REQUEST['province']);
		if ($province){
			$condition['province'] = $province;
		}
		$city= intval($_REQUEST['city']);
		if ($city){
			$condition['city'] = $city;
		}
		$area= intval($_REQUEST['area']);
		if ($area){
			$condition['area'] = $area;
		}
		//商户状态条件查询
		$pay_status = $_REQUEST[ 'pay_status' ];
        if ($pay_status != 'all' && !empty ($pay_status )){
              if ($pay_status == '-1' ){
                     $condition ['pay_status' ] = '0' ;
              } else {
                     $condition ['pay_status' ] = $pay_status;
              }
              
        }
        $status = $_REQUEST [ 'status'] ;
        if ($status != 'all' && !empty ($status )){
              if ($status == '-1' ){
                     $condition ['status' ] = '0' ;
              } else {
                     $condition ['status' ] = $status;
              }
        }
        $shipping_status = $_REQUEST [ 'shipping_status'] ;
        if ($shipping_status != 'all' && !empty ($shipping_status )){
              if ($shipping_status == '-1' ){
                     $condition ['shipping_status' ] = '0' ;
              } else {
                     $condition ['shipping_status' ] = $shipping_status;
              }
        }
	  	$checkout_status = $_REQUEST [ 'checkout_status'] ;
        if ($checkout_status != 'all' && !empty ($checkout_status )){
              if ($checkout_status == '-1' ){
                     $condition ['checkout_status' ] = '0' ;
              } else {
                     $condition ['checkout_status' ] = $checkout_status;
              }
        }

		
		$this -> assign($_REQUEST);
		$order=$this->orderField.' '.$this->orderDirection;
		$totalRows = $this->order->order_list($condition,'all');
		$this->assign ( "totalCount", $totalRows );
		if ($totalRows > 0) {
			$page = new Page ( $totalRows, $this->listrows );
			$pages=$page->show ();
			$list = $this->order->order_list($condition,$page->firstRow . ',' . $page->listRows ,$order);
			$this->assign('list',$list);
		}
		$this->display();
    }
	public function detail(){
		$id = intval ( $_REQUEST ['id'] );
		if(empty($id)){
            $this->_ajm(300,'请选择一条数据查看',0);
        }
		$info = $this->order->get_order_detail($id);
		if(empty($info)){
            $this->_ajm(300,'查询数据出错或者查询的数据不存在',0);
        }
		$ordergoods = $this->order->order_goods_list(array('order_id'=>$id));
		$log = $this->order->order_log_list(array('order_id'=>$id));
		$this->assign('info',$info);
		$this->assign('ordergoods',$ordergoods);
		$this->assign('log',$log);
		$this->display();
	}
	/**
	 * 判断订单上线是否存在
	 * @param array $agent_info 当前分销商区域内所有分销商
	 * @param array 	$order_area=array(
	 * 					'province' => 省份ID，
	 * 					'city' => 城市ID，
	 * 					'area' => 区域ID
	 * 					)
	 * @param array 	$accept_area=array(
	 * 					'province' => 省份ID，
	 * 					'city' => 城市ID，
	 * 					'area' => 区域ID
	 * 					)
	 * @return array
	 * */
	private function is_accept($agent_list=array(),$order_area=array(),$accept_area=array()){
		$temp_area = 0;
		$temp_city = 0;
		$temp_province = 0;
		foreach ($order_area as $key => $value) {
			//dump($value .'=='. $agent_list[$value]['vesting_'.$key].'=='.$agent_list[$value]['vesting_'.$key]);exit;
			if($value == $agent_list[$value]['vesting_'.$key]){
				//dump($accept_area);
				//dump($value .'=='. $agent_list[$value]['vesting_'.$key]);exit;
				if($this->_agent_area>0&&$agent_list[$value]['vesting_'.$key]==$this->_agent_area){
					//dump('aaa');
					foreach ($accept_area as $keys => $values) {
						//操作类型：0用户下单 受理：1代理商 2区专营商 3市专营商 4省专营商 5云采购
						//查看当前用户是否有受理或放弃订单记录;
						switch ($key) {
							case 'area':
								if($values['type']==2){
									return false;
								}
								break;
							case 'city':
								if($values['type']==3){
									return false;
								}
								break;
							case 'province':
								if($values['type']==4){
									return false;
								}
								break;
						}
					}
					//return true;
				}else{
					//dump('bbb');
					foreach ($accept_area as $keys => $values) {
						//操作类型：0用户下单 受理：1代理商 2区专营商 3市专营商 4省专营商 5云采购
						//查看当前用户是否有受理或放弃订单记录;
						//dump($key);
						switch ($key) {
							case 'area':
								if($values['type']==2){
									$temp_area = 2;
								}
								break;
							case 'city':
								if($values['type']==3){
									$temp_city = 3;
								}
								break;
							case 'province':
								if($values['type']==4){
									$temp_province = 4;
								}
								break;
						}
					}
				}
				//exit;
			}else{
				if(empty($agent_list[$value]['vesting_'.$key])){
					foreach ($accept_area as $keys => $values) {
						//操作类型：0用户下单 受理：1代理商 2区专营商 3市专营商 4省专营商 5云采购
						//查看当前用户是否有受理或放弃订单记录;
						switch ($key) {
							case 'area':
								$temp_area = 2;
								break;
							case 'city':
								$temp_city = 3;
								break;
							case 'province':
								$temp_province = 4;
								break;
						}
					}
				}
			}
		}
		if($temp_province==0&&$temp_city==0&&$temp_area==0){
			return false;
		}
		//dump($temp_province.$temp_city.$temp_area);exit;
		switch ($this->_agent_stype) {
			case 1://省
				if($temp_province == 4){
					return false;
				}
				if($temp_area == 2&&$temp_city == 3){
					return true;
				}else{
					return false;
				}
				break;
			case 2://市
				if($temp_city == 3){
					return false;
				}
				if($temp_area == 2){
					return true;
				}else{
					return false;
				}
				break;
			case 3://区
				if($temp_area == 0){
					return true;
				}
				break;
		}
		if($temp_area == 2&&$temp_city == 3&&$temp_province == 4){
			return true;
		}
	}
	//受理订单
	public function accept(){
		$id = intval ( $_REQUEST ['id'] );
		$province = intval ( $_REQUEST ['province'] );
		$city = intval ( $_REQUEST ['city'] );
		$area = intval ( $_REQUEST ['area'] );
		$start_time = intval ( $_REQUEST ['order_time'] );
		$userid = intval ( $_REQUEST ['order_user'] );
		$order_info = $this->order->get_order_detail($id);
		//获取订单所有商品
		$ordergoods = $this->order->order_goods_list(array('order_id'=>$id));
		//dump($order_info);exit;
		//dump(date('Y-m-d H:m:s',1382949661));exit;
		if(in_array($order_info['status'], array(6,7))){
			//$this->error (L('当前订单不在受理范围！'));
			$this->_ajm(300,'当前订单不在受理范围!',0);
		}
		//查询当前用户可用套件
		$kit = new Kit();
		$out_kit=array();//存储等待开通或其它操作的套件
		$i_out=0;
		//循环查询订单商品，type:商品类型，number:数量
		foreach ($ordergoods as $key => $value) {
			$where=array();
			//$where['userid']=$this->userid;
			$where['kp.type']=$value['type'];
			
			$where['province']=array('EQ', 0);
			$where['city']=array('EQ', 0);
			$where['area']=array('EQ', 0);
			$where['isclose']=array('EQ',0);
			/*switch ($this->_agent_stype) {
				case 1:
					$where['province']=$this->_province;
					$where['city']=array('EQ', 0);
					$where['area']=array('EQ', 0);
					$where['isclose']=array('EQ',0);
					break;
				case 2:
					$where['city']=$this->_city;
					$where['area']=array('EQ', 0);
					$where['isclose']=array('EQ',0);
					break;
				case 3:
					$where['area']=$this->_area;
					$where['isclose']=array('EQ',0);
					break;
				case 4:
					$where['isclose']=array('EQ',0);
					break;
			}*/
			$kit_list = $kit->kit_list($where,"0,".$value['number']);
			if(count($kit_list) != $value['number']){
				//$this->error (L('可用套件不足，请先进货'));
				//return '可用套件不足，请先进货!';
				$this->_ajm(300,'可用套件不足，请先生产套件!',0);
			}
			foreach ($kit_list as $keys => $values) {
				$out_kit[$i_out++]=$values;
			}
		}
		if(count($out_kit)!=$order_info['count_num']){
			$this->_ajm(300,'可用套件不足，请先生产套件!',0);
		}
		//查询订单最近上级是不是存在
		$agent = new Agent();
		$agent_info = $agent->agent_list('all',array('vesting_province'=>$province,'isclose'=>2));
		$order_area = array('area'=>$area,'city'=>$city,'province'=>$province);
		//$accept_area = $this->order->order_log_list(array('order_id'=>$id));
		$agent_list = array();
		foreach ($order_area as $key => $value) {
			foreach ($agent_info as $keys => $values) {
				if($value == $values['vesting_'.$key]){
					switch ($key) {
						case 'area':
							$agent_list[$value] = $values;
							break;
						case 'city':
							if($values['vesting_area']==0){
								$agent_list[$value] = $values;
							}
							break;
						case 'province':
							if($values['vesting_city']==0){
								$agent_list[$value] = $values;
							}
							break;
					}
				}
			}
		}
		//F('agent_list',$agent_list);exit;
		//查询订单用户归类
		$order_user_role = $agent->get_role($userid);
		
		$is_user_role = 0;
		foreach ($order_user_role as $key => $value) {
			if(in_array($value['role_id'], array(13,12,10,22))){//20,15
				$is_user_role = $value['role_id'];
			}
		}
		//dump($is_user_role);exit;
		$_info['id'] = $id;
		$_info['start_time'] = $start_time;
	  	$ret = $this->order->accept_order($_info,$userid,$this->_role,$this->userid);//$this->_role//要修改的权限编号
		//dump($ret);exit;
		$arr=object_array(json_decode($ret));
		if($arr['status']==1){
			//出货相关操作
			$ret_info = $this->out($id, $province, $city, $area, $start_time, $is_user_role, $order_info,$ordergoods,$out_kit);
			//支付受理XV
			//$this->assign ( 'jumpUrl', U('Admin/Kitsellorder/index') );
        	//$this->success (L($arr['msg'].$ret_info));
			$this->_ajm(200,$arr['msg'].$ret_info,0,U ( 'Kitorder/index' ));
		}else{
			//查询订单受理记录
			$accept_area = $this->order->order_log_list(array('order_id'=>$id));
			$ret = $this->is_accept($agent_list,$order_area,$accept_area);
			//dump($ret);exit;
			//dump($this->is_accept($agent_list,$order_area,$accept_area));exit;
			if(false!==$this->is_accept($agent_list,$order_area,$accept_area)){
				$accept_time = 0;
				foreach ($order_area as $key => $value) {
					//dump($key);
					switch ($key) {
						case 'area':
							$accept_time = strtotime("+24 hours", $start_time);
							break;
						case 'city':
							$accept_time = strtotime("+48 hours", $start_time);
							break;
						case 'province':
							$accept_time = strtotime("+72 hours", $start_time);
							break;
					}
					foreach ($agent_list as $keys => $values) {
						//dump($value .'=='. $values['vesting_'.$key]);
						if($value == $values['vesting_'.$key]){
							$_info['id'] = $id;
							$_info['start_time'] = $start_time;
							$ret = $this->order->accept_order($_info,$userid,$this->_role,$this->userid);
							//dump($ret);exit;
							$arr=object_array(json_decode($ret));
							if($arr['status']==1){
								//出货相关操作
								$ret_info = $this->out($id, $province, $city, $area, $start_time, $is_user_role, $order_info,$ordergoods,$out_kit);
								//支付受理XV
								//$this->assign ( 'jumpUrl', U('Admin/Kitsellorder/index') );
					        	//$this->success (L($arr['msg'].$ret_info));
								$this->_ajm(200,$arr['msg'].$ret_info,0,U ( 'Kitorder/index' ));
							}
						}
					}
					//exit;
					$_info['id'] = $id;
					$_info['start_time'] = $start_time;
					$res = $this->order->accept_order($_info,$userid,$this->_role,$this->userid,'分销用户不存在',$accept_time);
					//dump($res);exit;
					$arr=object_array(json_decode($res));
					if($arr['status']==0){
						//$this->error (L($arr['msg']));
						$this->_ajm(300,$arr['msg'],0);
					}
				}
			}else{
				if($arr['status']==0){
					//$this->error (L($arr['msg']));
					$this->_ajm(300,$arr['msg'],0);
				}
				//$this->error (L('现在您还不可以受理或等待您的下级受理'));
				$this->_ajm(300,'现在您还不可以受理或等待您的下级受理',0);
			}
		}
		//$this->display();
	}
	private function exist_order_type($orderlog,$type,$sort = false){
		$t_descount = 1;
		if($sort == true){
			sort($orderlog);
		}
		//dump($orderlog);
		foreach ($orderlog as $key => $value) {
			if($value['status']==1){
				if($type == $value['type']){
					//dump($value['type'] .'/'.$this->_agent_stype.'/'.$t_descount);exit;
					switch($value['type']){
						case 5:              
							break;                            
						case 4:                               
							return $t_descount;//$this->_arr_discount[1];
							break;
						case 3:
							return $t_descount;//$this->_arr_discount[2];
							break;
						case 2:
							return $t_descount;//$this->_arr_discount[3];
							break;
						case 1:
							return $t_descount;//$this->_arr_discount[4];
							break;
					}
				}else{
					switch($value['type']){
						case 5:              
							break;                            
						case 4:                               
							$t_descount = $this->_arr_discount[1];
							break;
						case 3:
							$t_descount = $this->_arr_discount[2];
							break;
						case 2:
							$t_descount = $this->_arr_discount[3];
							break;
						case 1:
							$t_descount = $this->_arr_discount[4];
							break;
					}
				}
			}
		}
	}
	//出货和完成订单
	private function out($id,$province,$city,$area,$start_time,$is_user_role,$order_info,$ordergoods,$out_kit){//$is_user_role $userid
		//订单受理状态
		$orderlog = $this->order->order_log_list(array('order_id'=>$id));
		//dump($orderlog);
		//受理成功后进行支付
		//是否放弃当前订单
		$is_status = 0;
		//当前受理用户下级受理用户的折扣
		$t_discount = 1;
		//dump($orderlog);exit;
		foreach ($orderlog as $key => $value) {
			switch($value['type']){
				case 5:
					if($this->_role == 14){
						if($value['status'] == 0){
							++$is_status;  
						}
					}
					break;
				case 4:
					if($this->_agent_stype == 1){
						if($value['status'] == 0){    
							++$is_status;             
							break;                    
						}                             
					}
					break;
				case 3:
					if($this->_agent_stype == 2){
						if($value['status'] == 0){
							++$is_status;
							break;
						}
					}
					break;
				case 2:
					if($this->_agent_stype == 3){
						if($value['status'] == 0){
							++$is_status;
							break;
						}
					}
					break;
				case 1:
					if($this->_agent_stype == 4){
						if($value['status'] == 0){
							++$is_status;
							break;
						}
					}
					break;
				case 0:
					break;
			}
		}
		if($is_status>0){
			//$this->error (L('您已放弃当前订单，不可出货!'));
			return '您已放弃当前订单，不可出货!';
		}
		$kit = new Kit();
		//实例支付
		$money=new KitMoney();
		//dump($t_discount);
		/*foreach ($orderlog as $key => $value) {
			if($value['status']==1){
				switch($value['type']){
					case 5:
						break;
					case 4:
						if($this->_agent_stype == 1){
							$t_discount = $this->exist_order_type($orderlog, $value['type'],true);   
							//dump($t_discount);    
						}
						break;
					case 3:
						if($this->_agent_stype == 2){
							$t_discount = $this->exist_order_type($orderlog, $value['type'],true);
						}
						break;
					case 2:
						if($this->_agent_stype == 3){
							$t_discount = $this->exist_order_type($orderlog, $value['type'],true);
						}
						break;
					case 1:
						if($this->_agent_stype == 4){
							$t_discount = $this->exist_order_type($orderlog, $value['type'],true);
						}
						break;
					case 0:
						break;
				}
			}
		}*/
		//dump($t_discount);
		if($this->_role == 14){
			$old_descount = 1;
			$new_descount = 1;
			$cur_descount = 1;
			sort($orderlog);
			//dump($orderlog);
			foreach ($orderlog as $key => $value) {
				if($value['status']==1){
					switch($value['type']){
						case 5:
							$old_descount = $cur_descount;
							break;
						case 4:
							/*if($this->_agent_stype == 1){
								$new_descount = $this->_arr_discount[1];
								$old_descount = $cur_descount;
							}*/
							$cur_descount = $this->_arr_discount[1];
							//return $t_descount;//$this->_arr_discount[1];
							break;
						case 3:
							/*if($this->_agent_stype == 2){
								$new_descount = $this->_arr_discount[2];
								$old_descount = $cur_descount;
							}*/
							$cur_descount = $this->_arr_discount[2];
							//return $t_descount;//$this->_arr_discount[2];
							break;
						case 2:
							/*if($this->_agent_stype == 3){
								$new_descount = $this->_arr_discount[3];
								$old_descount = $cur_descount;
							}*/
							$cur_descount = $this->_arr_discount[3];
							//return $t_descount;//$this->_arr_discount[3];
							break;
						case 1:
							/*if($this->_agent_stype == 4){
								$new_descount = $this->_arr_discount[4];
								$old_descount = 1;
							}*/
							$cur_descount = $this->_arr_discount[4];
							//return $t_descount;//$this->_arr_discount[4];
							break;
					}
				}
			}
			$t_discount = $old_descount;
			$t_money = $order_info['old_amount']/100*$old_descount;
			$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
		        	'action_userid'=>$this->userid,
		         	'cip'=>get_client_ip(),
		        	'bzvu'=>$order_info['sn'],
		         	'changtype'=>'KIT_ORDER_PAY_XV'
		         	));
		}
		/*dump($out_kit);exit;
		if(count($out_kit)!=$order_info['count_num']){
			$old_descount = 1;
			$new_descount = 1;
			$cur_descount = 1;
			sort($orderlog);
			foreach ($orderlog as $key => $value) {
				if($value['status']==1){
					switch($value['type']){
						case 5:
							break;
						case 4:
							if($this->_agent_stype == 1){
								$new_descount = $this->_arr_discount[1];
								$old_descount = $cur_descount;
							}
							$cur_descount = $this->_arr_discount[1];
							//return $t_descount;//$this->_arr_discount[1];
							break;
						case 3:
							if($this->_agent_stype == 2){
								$new_descount = $this->_arr_discount[2];
								$old_descount = $cur_descount;
							}
							$cur_descount = $this->_arr_discount[2];
							//return $t_descount;//$this->_arr_discount[2];
							break;
						case 2:
							if($this->_agent_stype == 3){
								$new_descount = $this->_arr_discount[3];
								$old_descount = $cur_descount;
							}
							$cur_descount = $this->_arr_discount[3];
							//return $t_descount;//$this->_arr_discount[3];
							break;
						case 1:
							if($this->_agent_stype == 4){
								$new_descount = $this->_arr_discount[4];
								$old_descount = 1;
							}
							$cur_descount = $this->_arr_discount[4];
							//return $t_descount;//$this->_arr_discount[4];
							break;
					}
				}
			}
			$t_pay_money = $order_info['old_amount']/100*$old_descount;
			$t_money = ($t_pay_money-($order_info['old_amount']/100*$new_descount));
			//支付XV
			$nowvalue = $money->recharge($this->userid,'XV',$t_pay_money,array(
		        	'action_userid'=>$this->userid,
		         	'cip'=>get_client_ip(),
		        	'bzvu'=>$order_info['sn'],
		         	'changtype'=>'KIT_ORDER_PAY_XV',
		         	'oper' => '-'
		         	));
			//结算XV到TV
			//dump($t_money);
			$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
		        	'action_userid'=>$this->userid,
		         	'cip'=>get_client_ip(),
		        	'bzvu'=>$order_info['sn'],
		         	'changtype'=>'KIT_ORDER_RECE_TV',
		         	'oper' => '-'
		         	));
			//结算存入TV
			//dump($t_money);
			$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
		        	'action_userid'=>$this->userid,
		         	'cip'=>get_client_ip(),
		        	'bzvu'=>$order_info['sn'],
		         	'changtype'=>'KIT_ORDER_RECE_TV'
		         	));
					//exit;
			return '套件不足未出货，等待上级处理!';
		}*/
		rsort($orderlog);
		//分销商用户类实例
		$agent = new Agent();
		//云购平台信息
		$biz = new Biz();
		//type 操作类型：0用户下单 
		//操作归属开通
		if(count($out_kit) == 1){
			//操作归属开通
			if($is_user_role == 0){
				//开通用户类型：1云购商  2云购店  3代理商
				switch ($out_kit[0]['kp_type']) {
					case 1:
						//操作归属
						$cloudsn = '';
						//合约开始时间
						$contract_start_time = 0;
						//合约结束时间
						$contract_end_time = 0;
						//上级分销商ID
						$agent_superior = 0;
						//上层受理分销折扣
						//$kit_discount = 1;
						//dump($orderlog);exit;
						foreach ($orderlog as $key => $value) {
							if($contract_start_time==0){
								$contract_start_time = $value['ctime'];
								$contract_end_time = strtotime("+1 year",$contract_start_time);
							}
							//受理用户组：1代理商 2区专营商 3市专营商 4省专营商 5云采购
							if($value['status']==1){
								switch ($value['type']) {
									case 5:
										//云采购
										//exit;
										break;
									case 4:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：1省专营商
										if($this->_agent_stype == 1){
											break;
										}else{
											if(empty($cloudsn)){
												
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										//$kit_discount = $this->_arr_discount[1];
										$agent_superior = $value['action_userid'];
										break;
									case 3:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：2市专营商
										if($this->_agent_stype == 2){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										//$kit_discount = $this->_arr_discount[2];
										$agent_superior = $value['action_userid'];
										break;
									case 2:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：3区专营商
										if($this->_agent_stype == 3){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										//$kit_discount = $this->_arr_discount[3];
										$agent_superior = $value['action_userid'];
										break;
									case 1:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：4代理商
										if($this->_agent_stype == 4){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										//$kit_discount = $this->_arr_discount[4];
										$agent_superior = $value['action_userid'];
										break;
									case 0:
										//归属给订单会员
										if(empty($cloudsn)){
											$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],15,$agent_superior,'测试归属');
											$arr=object_array(json_decode($ret));
											if($arr['status']==1){
												$cloudsn=$arr['cloudsn'];
											}
										}else{
											$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],15,$agent_superior,'测试归属');
											$arr=object_array(json_decode($ret));
											if($arr['status']==1){
												$cloudsn=$arr['cloudsn'];
											}
										}
										  /////////////////////////////////
										 //			处理订单				//
										/////////////////////////////////
										
										//出货状态
										$this->order->order_shipping_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成出货');
										//订单状态
										$this->order->order_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成订单');
										//结算状态
										$this->order->order_checkout_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'订单结算');
										//结算体系
										//当前订单支付后结算金额
										//$t_money = $order_info['amount']/100;
										$t_money = ($order_info['old_amount']/100*$t_discount);
										//结算XV到TV
										$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
									        	'action_userid'=>$this->userid,
									         	'cip'=>get_client_ip(),
									        	'bzvu'=>$order_info['sn'],
									         	'changtype'=>'KIT_ORDER_RECE_TV',
									         	'oper' => '-'
									         	));
										//结算存入TV
										$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
									        	'action_userid'=>$this->userid,
									         	'cip'=>get_client_ip(),
									        	'bzvu'=>$order_info['sn'],
									         	'changtype'=>'KIT_ORDER_RECE_TV'
									         	));
										  /////////////////////////////////
										 //			开通套件				//
										/////////////////////////////////
										
										//开始时间=结束时间
										$kit->kit_edit(array('id'=>$out_kit[0]['id'],'starttime'=>$contract_start_time,'endtime'=>$contract_end_time),array(),array(),$agent_superior,'系统生成合约时间');
										//套件状态
										$kit->kit_isclose(array('id'=>$out_kit[0]['id'],'isclose'=>2),array(),array(),$agent_superior,'开通套件');
										  /////////////////////////////////
										 //		       开通云购商			//
										/////////////////////////////////
										$biz_info = $biz->get_biz_detail('',$value['action_userid']);
										if(!empty($biz_info)){
											//开始时间=结束时间 
											$biz->biz_edit(array('id'=>$biz_info['id'],'starttime'=>$contract_start_time,'endtime'=>$contract_end_time),array(),array(),$value['action_userid'],$agent_superior,'系统生成合约时间');
											//支付状态
											$biz->biz_pay_status($biz_info['id'],$value['action_userid'],$agent_superior,4,'线上支付');
											//处理状态
											$biz->biz_status($biz_info['id'],$value['action_userid'],$agent_superior,2,'审核帐户');
											//开通状态
											$biz->biz_isclose($biz_info['id'],$value['action_userid'],$agent_superior,2,15,'开通帐户');
										}
										break;
								}
							}
							
						}
						break;
					case 2:
						//操作归属
						$cloudsn = '';
						//合约开始时间
						$contract_start_time = 0;
						//合约结束时间
						$contract_end_time = 0;
						//上级分销商ID
						$agent_superior = 0;
						//上层受理分销折扣
						//$kit_discount = 1;
						foreach ($orderlog as $key => $value) {
							if($contract_start_time==0){
								$contract_start_time = $value['ctime'];
								$contract_end_time = strtotime("+1 year",$contract_start_time);
							}
							//受理用户组：1代理商 2区专营商 3市专营商 4省专营商 5云采购
							if($value['status']==1){
								switch ($value['type']) {
									case 5:
										//云采购
										//exit;
										break;
									case 4:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：1省专营商
										if($this->_agent_stype == 1){
											break;
										}else{
											if(empty($cloudsn)){
												
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										//$kit_discount = $this->_arr_discount[1];
										$agent_superior = $value['action_userid'];
										break;
									case 3:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：2市专营商
										if($this->_agent_stype == 2){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										//$kit_discount = $this->_arr_discount[2];
										$agent_superior = $value['action_userid'];
										break;
									case 2:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：3区专营商
										if($this->_agent_stype == 3){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										//$kit_discount = $this->_arr_discount[3];
										$agent_superior = $value['action_userid'];
										break;
									case 1:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：4代理商
										if($this->_agent_stype == 4){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										//$kit_discount = $this->_arr_discount[4];
										$agent_superior = $value['action_userid'];
										break;
									case 0:
										//归属给订单会员
										if(empty($cloudsn)){
											$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],20,$agent_superior,'测试归属');
											$arr=object_array(json_decode($ret));
											if($arr['status']==1){
												$cloudsn=$arr['cloudsn'];
											}
										}else{
											$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],20,$agent_superior,'测试归属');
											$arr=object_array(json_decode($ret));
											if($arr['status']==1){
												$cloudsn=$arr['cloudsn'];
											}
										}
										  /////////////////////////////////
										 //			处理订单				//
										/////////////////////////////////
										
										//出货状态
										$this->order->order_shipping_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成出货');
										//订单状态
										$this->order->order_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成订单');
										//结算状态
										$this->order->order_checkout_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'订单结算');
										//结算体系
										//当前订单支付后结算金额
										//$t_money = $order_info['amount']/100;
										$t_money = ($order_info['old_amount']/100*$t_discount);
										//结算XV到TV
										$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
									        	'action_userid'=>$this->userid,
									         	'cip'=>get_client_ip(),
									        	'bzvu'=>$order_info['sn'],
									         	'changtype'=>'KIT_ORDER_RECE_TV',
									         	'oper' => '-'
									         	));
										//结算存入TV
										$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
									        	'action_userid'=>$this->userid,
									         	'cip'=>get_client_ip(),
									        	'bzvu'=>$order_info['sn'],
									         	'changtype'=>'KIT_ORDER_RECE_TV'
									         	));
										  /////////////////////////////////
										 //			开通套件				//
										/////////////////////////////////
										
										//开始时间=结束时间
										$kit->kit_edit(array('id'=>$out_kit[0]['id'],'starttime'=>$contract_start_time,'endtime'=>$contract_end_time),array(),array(),$agent_superior,'系统生成合约时间');
										//套件状态
										$kit->kit_isclose(array('id'=>$out_kit[0]['id'],'isclose'=>2),array(),array(),$agent_superior,'开通套件');
										  /////////////////////////////////
										 //		       开通云购商			//
										/////////////////////////////////
										$biz_info = $biz->get_biz_detail('',$value['action_userid']);
										if(!empty($biz_info)){
											//开始时间=结束时间 
											$biz->biz_edit(array('id'=>$biz_info['id'],'starttime'=>$contract_start_time,'endtime'=>$contract_end_time),array(),array(),$value['action_userid'],$agent_superior,'系统生成合约时间');
											//支付状态
											$biz->biz_pay_status($biz_info['id'],$value['action_userid'],$agent_superior,4,'线上支付');
											//处理状态
											$biz->biz_status($biz_info['id'],$value['action_userid'],$agent_superior,2,'审核帐户');
											//开通状态
											$biz->biz_isclose($biz_info['id'],$value['action_userid'],$agent_superior,2,20,'开通帐户');
										}
										break;
								}
							}
							
						}
						break;
					case 3:
						//操作归属
						$cloudsn = '';
						//合约开始时间
						$contract_start_time = 0;
						//合约结束时间
						$contract_end_time = 0;
						//上级分销商ID
						$agent_superior = 0;
						//上层受理分销折扣
						//$kit_discount = 1;
						foreach ($orderlog as $key => $value) {
							if($contract_start_time==0){
								$contract_start_time = $value['ctime'];
								$contract_end_time = strtotime("+1 year",$contract_start_time);
							}
							//受理用户组：1代理商 2区专营商 3市专营商 4省专营商 5云采购
							if($value['status']==1){
								switch ($value['type']) {
									case 5:
										//云采购
										//exit;
										break;
									case 4:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：1省专营商
										if($this->_agent_stype == 1){
											break;
										}else{
											if(empty($cloudsn)){
												
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										//$kit_discount = $this->_arr_discount[1];
										$agent_superior = $value['action_userid'];
										break;
									case 3:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：2市专营商
										if($this->_agent_stype == 2){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										//$kit_discount = $this->_arr_discount[2];
										$agent_superior = $value['action_userid'];
										break;
									case 2:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：3区专营商
										if($this->_agent_stype == 3){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										//$kit_discount = $this->_arr_discount[3];
										$agent_superior = $value['action_userid'];
										break;
									case 1:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：4代理商
										if($this->_agent_stype == 4){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										//$kit_discount = $this->_arr_discount[4];
										$agent_superior = $value['action_userid'];
										break;
									case 0:
										//归属给订单会员
										if(empty($cloudsn)){
											$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],15,$agent_superior,'测试归属');
											$arr=object_array(json_decode($ret));
											if($arr['status']==1){
												$cloudsn=$arr['cloudsn'];
											}
										}else{
											$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],15,$agent_superior,'测试归属');
											$arr=object_array(json_decode($ret));
											if($arr['status']==1){
												$cloudsn=$arr['cloudsn'];
											}
										}
										  /////////////////////////////////
										 //			处理订单				//
										/////////////////////////////////
										
										//出货状态
										$this->order->order_shipping_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成出货');
										//订单状态
										$this->order->order_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成订单');
										//结算状态
										$this->order->order_checkout_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'订单结算');
										//结算体系
										//当前订单支付后结算金额
										//$t_money = $order_info['amount']/100;
										$t_money = ($order_info['old_amount']/100*$t_discount);
										//结算XV到TV
										$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
									        	'action_userid'=>$this->userid,
									         	'cip'=>get_client_ip(),
									        	'bzvu'=>$order_info['sn'],
									         	'changtype'=>'KIT_ORDER_RECE_TV',
									         	'oper' => '-'
									         	));
										//结算存入TV
										$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
									        	'action_userid'=>$this->userid,
									         	'cip'=>get_client_ip(),
									        	'bzvu'=>$order_info['sn'],
									         	'changtype'=>'KIT_ORDER_RECE_TV'
									         	));
										  /////////////////////////////////
										 //			开通套件				//
										/////////////////////////////////
										
										//开始时间=结束时间
										$kit->kit_edit(array('id'=>$out_kit[0]['id'],'starttime'=>$contract_start_time,'endtime'=>$contract_end_time),array(),array(),$agent_superior,'系统生成合约时间');
										//套件状态
										$kit->kit_isclose(array('id'=>$out_kit[0]['id'],'isclose'=>2),array(),array(),$agent_superior,'开通套件');
										  /////////////////////////////////
										 //		       开通云购商			//
										/////////////////////////////////
										$biz_info = $biz->get_biz_detail('',$value['action_userid']);
										if(!empty($biz_info)){
											//开始时间=结束时间 
											$biz->biz_edit(array('id'=>$biz_info['id'],'starttime'=>$contract_start_time,'endtime'=>$contract_end_time),array(),array(),$value['action_userid'],$agent_superior,'系统生成合约时间');
											//支付状态
											$biz->biz_pay_status($biz_info['id'],$value['action_userid'],$agent_superior,4,'线上支付');
											//处理状态
											$biz->biz_status($biz_info['id'],$value['action_userid'],$agent_superior,2,'审核帐户');
											//开通状态
											$biz->biz_isclose($biz_info['id'],$value['action_userid'],$agent_superior,2,15,'开通帐户');
										}
										break;
								}
							}
							
						}
						break;
				}
			}else{
				switch ($out_kit[0]['kp_type']) {
					case 1:
						//操作归属
						$cloudsn = '';
						//合约开始时间
						$contract_start_time = 0;
						//合约结束时间
						$contract_end_time = 0;
						//上级分销商ID
						$agent_superior = 0;
						//受理订单记录条数
						$orderlog_length = count($orderlog);
						//上层受理分销折扣
						//$kit_discount = 1;
						//dump($orderlog);exit;
						foreach ($orderlog as $key => $value) {
							if($contract_start_time==0){
								$contract_start_time = $value['ctime'];
								$contract_end_time = strtotime("+1 year",$contract_start_time);
							}
							//受理用户组：1代理商 2区专营商 3市专营商 4省专营商 5云采购
							if($value['status']==1){
								//dump($value);exit;
								switch ($value['type']) {
									case 5:
										//云采购
										if($orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$value['user_id'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$value['user_id'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$value['user_id'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $value['type']);
											//dump($t_discount);
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//dump($t_money);exit;
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
									case 4:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：1省专营商
										if($this->_agent_stype == 1){
											break;
										}else{
											if(empty($cloudsn)){
												
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $value['action_userid'];
										if($orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $value['type']);
											//dump($t_discount);
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//dump($t_money);exit;
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										//$kit_discount = $this->_arr_discount[1];
										break;
									case 3:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：2市专营商
										if($this->_agent_stype == 2){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $value['action_userid'];
										if($orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										//$kit_discount = $this->_arr_discount[2];
										break;
									case 2:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：3区专营商
										if($this->_agent_stype == 3){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $value['action_userid'];
										if($orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $value['type']);
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										//$kit_discount = $this->_arr_discount[3];
										break;
									case 1:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：4代理商
										if($this->_agent_stype == 4){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $value['action_userid'];
										if($orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										//$kit_discount = $this->_arr_discount[4];
										break;
								}
							}
							$orderlog_length--;
						}
						break;
					case 2:
						//操作归属
						$cloudsn = '';
						//合约开始时间
						$contract_start_time = 0;
						//合约结束时间
						$contract_end_time = 0;
						//上级分销商ID
						$agent_superior = 0;
						//受理订单记录条数
						$orderlog_length = count($orderlog);
						foreach ($orderlog as $key => $value) {
							if($contract_start_time==0){
								$contract_start_time = $value['ctime'];
								$contract_end_time = strtotime("+1 year",$contract_start_time);
							}
							//受理用户组：1代理商 2区专营商 3市专营商 4省专营商 5云采购
							if($value['status']==1){
								switch ($value['type']) {
									case 5:
										//云采购
										//exit;
										break;
									case 4:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：1省专营商
										if($this->_agent_stype == 1){
											break;
										}else{
											if(empty($cloudsn)){
												
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $value['action_userid'];
										if($orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
									case 3:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：2市专营商
										if($this->_agent_stype == 2){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $value['action_userid'];
										if($orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
									case 2:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：3区专营商
										if($this->_agent_stype == 3){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $value['action_userid'];
										if($orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
									case 1:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：4代理商
										if($this->_agent_stype == 4){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $value['action_userid'];
										if($orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
								}
							}
							$orderlog_length--;
						}
						break;
					case 3:
						//操作归属
						$cloudsn = '';
						//合约开始时间
						$contract_start_time = 0;
						//合约结束时间
						$contract_end_time = 0;
						//上级分销商ID
						$agent_superior = 0;
						//受理订单记录条数
						$orderlog_length = count($orderlog);
						foreach ($orderlog as $key => $value) {
							if($contract_start_time==0){
								$contract_start_time = $value['ctime'];
								$contract_end_time = strtotime("+1 year",$contract_start_time);
							}
							//受理用户组：1代理商 2区专营商 3市专营商 4省专营商 5云采购
							if($value['status']==1){
								switch ($value['type']) {
									case 5:
										//云采购
										//exit;
										break;
									case 4:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：1省专营商
										if($this->_agent_stype == 1){
											break;
										}else{
											if(empty($cloudsn)){
												
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $value['action_userid'];
										if($orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
									case 3:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：2市专营商
										if($this->_agent_stype == 2){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $value['action_userid'];
										if($orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
									case 2:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：3区专营商
										if($this->_agent_stype == 3){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $value['action_userid'];
										if($orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
									case 1:
										if($agent_superior == 0){
											$agent_superior = $value['action_userid'];
										}
										//当前分销商：4代理商
										if($this->_agent_stype == 4){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $out_kit[0]['cloudsn'],
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $out_kit[0]['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type']
																	 ),array(),array(),$value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $value['action_userid'];
										if($orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
								}
							}
							$orderlog_length--;
						}
						break;
				}
			}
		}
		//订单多个商品
		if(count($out_kit) > 1){
			//dump($orderlog);
			//$orderlog = $this->order->order_log_list(array('order_id'=>$id),0,'id ASC');
			//dump($orderlog);
			//订单商品条数
			$out_kit_length = count($out_kit);
			//操作套件出库 
			foreach ($out_kit as $key => $value) {
				//dump($value['kp_type']);
				switch ($value['kp_type']) {
					case 1:
						//操作归属
						$cloudsn = '';
						//合约开始时间
						$contract_start_time = 0;
						//合约结束时间
						$contract_end_time = 0;
						//上级分销商ID
						$agent_superior = 0;
						//受理订单记录条数
						$orderlog_length = count($orderlog);
						foreach ($orderlog as $_key => $_value) {
							if($contract_start_time==0){
								$contract_start_time = $_value['ctime'];
								$contract_end_time = strtotime("+1 year",$contract_start_time);
							}
							//受理用户组：1代理商 2区专营商 3市专营商 4省专营商 5云采购
							if($_value['status']==1){
								//dump($_value['type']);
								switch ($_value['type']) {
									case 5:
										//云采购
										//exit;
										break;
									case 4:
										if($agent_superior == 0){
											$agent_superior = $_value['action_userid'];
										}
										//当前分销商：1省专营商
										if($this->_agent_stype == 1){
											break;
										}else{
											if(empty($cloudsn)){
												
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $value['cloudsn'],
																	 'type' => $value['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$_value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $out_kit[0]['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$_value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $_value['action_userid'];
										if($out_kit_length == 1 && $orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $_value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
									case 3:
										if($agent_superior == 0){
											$agent_superior = $_value['action_userid'];
										}
										//当前分销商：2市专营商
										if($this->_agent_stype == 2){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $value['cloudsn'],
																	 'type' => $value['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$_value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $value['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$_value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $_value['action_userid'];
										if($out_kit_length == 1 && $orderlog_length == 1){
											//dump($kit_discount);dump(3);exit;
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $_value['type']);
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
									case 2:
										if($agent_superior == 0){
											$agent_superior = $_value['action_userid'];
										}
										//当前分销商：3区专营商
										if($this->_agent_stype == 3){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $value['cloudsn'],
																	 'type' => $value['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$_value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $value['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$_value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $_value['action_userid'];
										if($out_kit_length == 1&& $orderlog_length == 1){// 
											//dump($kit_discount);dump(2);exit;
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $_value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
									case 1:
										if($agent_superior == 0){
											$agent_superior = $_value['action_userid'];
										}
										//当前分销商：4代理商
										if($this->_agent_stype == 4){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $value['cloudsn'],
																	 'type' => $value['kp_type']
																	 ),array(),array(),$_value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $value['kp_type']
																	 ),array(),array(),$_value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $_value['action_userid'];
										if($out_kit_length == 1 && $orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $_value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
								}
							}
							$orderlog_length--;
						}
						break;
					case 2:
						//操作归属
						$cloudsn = '';
						//合约开始时间
						$contract_start_time = 0;
						//合约结束时间
						$contract_end_time = 0;
						//上级分销商ID
						$agent_superior = 0;
						//受理订单记录条数
						$orderlog_length = count($orderlog);
						foreach ($orderlog as $_key => $_value) {
							if($contract_start_time==0){
								$contract_start_time = $_value['ctime'];
								$contract_end_time = strtotime("+1 year",$contract_start_time);
							}
							//受理用户组：1代理商 2区专营商 3市专营商 4省专营商 5云采购
							if($_value['status']==1){
								switch ($_value['type']) {
									case 5:
										//云采购
										//exit;
										break;
									case 4:
										if($agent_superior == 0){
											$agent_superior = $_value['action_userid'];
										}
										//当前分销商：1省专营商
										if($this->_agent_stype == 1){
											break;
										}else{
											if(empty($cloudsn)){
												
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $value['cloudsn'],
																	 'type' => $value['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$_value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $value['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$_value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $_value['action_userid'];
										if($out_kit_length == 1 && $orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $_value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
									case 3:
										if($agent_superior == 0){
											$agent_superior = $_value['action_userid'];
										}
										//当前分销商：2市专营商
										if($this->_agent_stype == 2){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $value['cloudsn'],
																	 'type' => $value['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$_value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $value['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$_value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $_value['action_userid'];
										if($out_kit_length == 1 && $orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $_value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
									case 2:
										if($agent_superior == 0){
											$agent_superior = $_value['action_userid'];
										}
										//当前分销商：3区专营商
										if($this->_agent_stype == 3){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $value['cloudsn'],
																	 'type' => $value['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$_value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $value['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$_value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $_value['action_userid'];
										if($out_kit_length == 1 && $orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $_value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
									case 1:
										if($agent_superior == 0){
											$agent_superior = $_value['action_userid'];
										}
										//当前分销商：4代理商
										if($this->_agent_stype == 4){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $value['cloudsn'],
																	 'type' => $value['kp_type']
																	 ),array(),array(),$_value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $value['kp_type']
																	 ),array(),array(),$_value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $_value['action_userid'];
										if($out_kit_length == 1 && $orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $_value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
								}
							}
							$orderlog_length--;
						}
						break;
					case 3:
						//操作归属
						$cloudsn = '';
						//合约开始时间
						$contract_start_time = 0;
						//合约结束时间
						$contract_end_time = 0;
						//上级分销商ID
						$agent_superior = 0;
						//受理订单记录条数
						$orderlog_length = count($orderlog);
						foreach ($orderlog as $_key => $_value) {
							if($contract_start_time==0){
								$contract_start_time = $_value['ctime'];
								$contract_end_time = strtotime("+1 year",$contract_start_time);
							}
							//受理用户组：1代理商 2区专营商 3市专营商 4省专营商 5云采购
							if($_value['status']==1){
								switch ($_value['type']) {
									case 5:
										//云采购
										//exit;
										break;
									case 4:
										if($agent_superior == 0){
											$agent_superior = $_value['action_userid'];
										}
										//当前分销商：1省专营商
										if($this->_agent_stype == 1){
											break;
										}else{
											if(empty($cloudsn)){
												
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $value['cloudsn'],
																	 'type' => $value['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$_value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $value['kp_type'],
																	 'province_cn' => $this->area_list[$province]['name'],
																	 'province' => $province
																	 ),array(),array(),$_value['action_userid'],13,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $_value['action_userid'];
										if($out_kit_length == 1 && $orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $_value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
									case 3:
										if($agent_superior == 0){
											$agent_superior = $_value['action_userid'];
										}
										//当前分销商：2市专营商
										if($this->_agent_stype == 2){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $value['cloudsn'],
																	 'type' => $value['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$_value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $value['kp_type'],
																	 'city_cn' => $this->area_list[$city]['name'],
																	 'city' => $city
																	 ),array(),array(),$_value['action_userid'],12,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $_value['action_userid'];
										if($out_kit_length == 1 && $orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $_value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
									case 2:
										if($agent_superior == 0){
											$agent_superior = $_value['action_userid'];
										}
										//当前分销商：3区专营商
										if($this->_agent_stype == 3){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $value['cloudsn'],
																	 'type' => $value['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$_value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $value['kp_type'],
																	 'area_cn' => $this->area_list[$area]['name'],
																	 'area' => $area
																	 ),array(),array(),$_value['action_userid'],10,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $_value['action_userid'];
										if($out_kit_length == 1 && $orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $_value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
									case 1:
										if($agent_superior == 0){
											$agent_superior = $_value['action_userid'];
										}
										//当前分销商：4代理商
										if($this->_agent_stype == 4){
											break;
										}else{
											if(empty($cloudsn)){
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $value['cloudsn'],
																	 'type' => $value['kp_type']
																	 ),array(),array(),$_value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}else{
												$ret=$kit->kit_vesting(array(
																	 'id' => $value['id'],
																	 'cloudsn' => $cloudsn,
																	 'type' => $value['kp_type']
																	 ),array(),array(),$_value['action_userid'],22,$agent_superior,'测试归属');
												$arr=object_array(json_decode($ret));
												if($arr['status']==1){
													$cloudsn=$arr['cloudsn'];
												}
											}
										}
										$agent_superior = $_value['action_userid'];
										if($out_kit_length == 1 && $orderlog_length == 1){
											  /////////////////////////////////
											 //			处理订单				//
											/////////////////////////////////
											
											//出货状态
											$this->order->order_shipping_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成出货');
											//订单状态
											$this->order->order_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'完成订单');
											//结算状态
											$this->order->order_checkout_status(array('id'=>$id),$_value['action_userid'],$this->_role,$this->userid,'订单结算');
											//结算体系
											//当前订单支付后结算金额
											//$t_discount = $this->exist_order_type($orderlog, $_value['type']);
											//dump($t_discount);exit;
											$t_money = ($order_info['old_amount']/100*$t_discount);
											//结算XV到TV
											$nowvalue = $money->recharge($this->userid,'XV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV',
										         	'oper' => '-'
										         	));
											//结算存入TV
											$nowvalue = $money->recharge($this->userid,'TV',$t_money,array(
										        	'action_userid'=>$this->userid,
										         	'cip'=>get_client_ip(),
										        	'bzvu'=>$order_info['sn'],
										         	'changtype'=>'KIT_ORDER_RECE_TV'
										         	));
										}
										break;
								}
							}
							$orderlog_length--;
						}
						break;
				}
				$out_kit_length--;
			}//exit;
		}
	}
}